package indi.zhifa.study2025.oa.admin.controller;

import indi.zhifa.engine.core.common.web.ann.ZhiFaRestController;
import indi.zhifa.study2025.oa.admin.facade.menu.IAppFacade;
import indi.zhifa.study2025.oa.common.util.ConstantUtil;
import indi.zhifa.study2025.oa.model.enums.EAppStatus;
import indi.zhifa.study2025.oa.model.expose.menu.dto.AppCreateDto;
import indi.zhifa.study2025.oa.model.expose.menu.dto.AppEditDto;
import indi.zhifa.study2025.oa.model.expose.menu.vo.AppVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Validated
@RequiredArgsConstructor
@Tag(name = "应用接口")
@ZhiFaRestController
@RequestMapping(ConstantUtil.API_PREFIX + "/appMgr")
public class AppController {

    final IAppFacade mAppFacade;

    @Operation(summary = "创建应用")
    @PostMapping
    public AppVo create(@RequestBody AppCreateDto pCreateDto){
        AppVo rtn = mAppFacade.create(pCreateDto);
        return rtn;
    }

    @Operation(summary = "编辑应用")
    @PostMapping("/{id}/edit")
    public AppVo edit(@PathVariable("id") Long pId, @RequestBody AppEditDto pEditDto){
        AppVo rtn = mAppFacade.edit(pId, pEditDto);
        return rtn;
    }

    @Operation(summary = "设置状态")
    @PostMapping("/{id}/status")
    public AppVo setStatus(@PathVariable("id") Long pId, @RequestParam("status") EAppStatus pStatus){
        AppVo rtn = mAppFacade.setStatus(pId, pStatus);
        return rtn;
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    public AppVo delete(@PathVariable("id") Long pId){
        AppVo rtn = mAppFacade.delete(pId);
        return rtn;
    }

    @Operation(summary = "info")
    @GetMapping("/{id}")
    public AppVo info(@PathVariable("id") Long pId){
        AppVo rtn = mAppFacade.info(pId);
        return rtn;
    }

}
